package com.pulp.production.action;

import java.util.List;

import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;

import org.apache.log4j.Logger;
import org.apache.struts2.ServletActionContext;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.pulp.production.service.ProductionInfoService;
import com.se.model.CommonSessionUser;

public class PaperMachineAction<ProductionInfo> extends ActionSupport {
	private static final long serialVersionUID = -734632013410514139L;
	private String REQUEST_RESULT = "ok";
	static Logger logger = Logger.getLogger(PaperMachineAction.class);

	private String errorCode = "";

	private List paperMachineYearList = null;
	private List paperMachineMonthList = null;
	private List paperMachineDateList = null;

	/**
	 * @return the rEQUEST_RESULT
	 */
	public String getREQUEST_RESULT() {
		return REQUEST_RESULT;
	}

	/**
	 * @param rEQUEST_RESULT the rEQUEST_RESULT to set
	 */
	public void setREQUEST_RESULT(String rEQUEST_RESULT) {
		REQUEST_RESULT = rEQUEST_RESULT;
	}

	/**
	 * @return the logger
	 */
	public static Logger getLogger() {
		return logger;
	}

	/**
	 * @param logger the logger to set
	 */
	public static void setLogger(Logger logger) {
		PaperMachineAction.logger = logger;
	}

	/**
	 * @return the errorCode
	 */
	public String getErrorCode() {
		return errorCode;
	}

	/**
	 * @param errorCode the errorCode to set
	 */
	public void setErrorCode(String errorCode) {
		this.errorCode = errorCode;
	}

	/**
	 * @return the paperMachineYearList
	 */
	public List getPaperMachineYearList() {
		return paperMachineYearList;
	}

	/**
	 * @param paperMachineYearList the paperMachineYearList to set
	 */
	public void setPaperMachineYearList(List paperMachineYearList) {
		this.paperMachineYearList = paperMachineYearList;
	}

	/**
	 * @return the paperMachineMonthList
	 */
	public List getPaperMachineMonthList() {
		return paperMachineMonthList;
	}

	/**
	 * @param paperMachineMonthList the paperMachineMonthList to set
	 */
	public void setPaperMachineMonthList(List paperMachineMonthList) {
		this.paperMachineMonthList = paperMachineMonthList;
	}

	/**
	 * @return the paperMachineDateList
	 */
	public List getPaperMachineDateList() {
		return paperMachineDateList;
	}

	/**
	 * @param paperMachineDateList the paperMachineDateList to set
	 */
	public void setPaperMachineDateList(List paperMachineDateList) {
		this.paperMachineDateList = paperMachineDateList;
	}

	public PaperMachineAction() {}

	public String excute() throws Exception {

		try {

			HttpServletRequest request = (HttpServletRequest) ServletActionContext.getRequest();
			ActionContext context = ActionContext.getContext();
			CommonSessionUser user = (CommonSessionUser) request.getSession().getAttribute(CommonSessionUser.ATTRIBUTE_NAME);
			ServletContext servletContext = ServletActionContext.getServletContext();
			WebApplicationContext wac = WebApplicationContextUtils.getWebApplicationContext(servletContext);
			ProductionInfoService productionInfoService = (ProductionInfoService) wac.getBean("productionInfoService");

			paperMachineYearList = productionInfoService.getPaperMachineYear();
			paperMachineMonthList = productionInfoService.getPaperMachineMonth();
			paperMachineDateList = productionInfoService.getPaperMachineDate();

			request.setAttribute("paperMachineYearList", paperMachineYearList);
			request.setAttribute("paperMachineMonthList", paperMachineMonthList);
			request.setAttribute("paperMachineDateList", paperMachineDateList);

		} catch (Exception ex) {
			REQUEST_RESULT = "FAILED";
			ex.printStackTrace();
		}
		return REQUEST_RESULT;
	}

}